Skip to content

Update deprecated functions in Box::leak example#1992

Merged
marioidival merged 1 commit intorust-lang:masterfrom
anselbobrow:patch-1
Jan 25, 2026
Merged

Update deprecated functions in Box::leak example#1992
marioidival merged 1 commit intorust-lang:masterfrom
anselbobrow:patch-1

Conversation

@anselbobrow
Copy link
Copy Markdown
Contributor

Fixes #1922

Previously, this example wasn't compiling because of the deprecated thread_rng and fill functions. Upon making the changes the compiler suggests and swapping usize for u64, the example compiles properly. Here are the compiler errors:

Compiling playground v0.0.1 (/playground)
warning: unused import: `rand::Fill`
 --> src/main.rs:2:5
  |
2 | use rand::Fill;
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: use of deprecated function `rand::thread_rng`: Renamed to `rng`
 --> src/main.rs:5:25
  |
5 |     let mut rng = rand::thread_rng();
  |                         ^^^^^^^^^^
  |
  = note: `#[warn(deprecated)]` on by default

error[E0599]: no method named `try_fill` found for struct `Box<[{integer}; 100]>` in the current scope
 --> src/main.rs:7:11
  |
7 |     boxed.try_fill(&mut rng).unwrap();
  |           ^^^^^^^^
  |
help: there is a method `fill` with a similar name
  |
7 -     boxed.try_fill(&mut rng).unwrap();
7 +     boxed.fill(&mut rng).unwrap();
  |

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compilation failure of example code in 15.4.8 Scoping rules / Lifetimes / Static

3 participants